import { Component } from 'react';
import { onEmit, onListen } from '../utils/request'
import { topicConstants } from '../constants/topicConstants'


class Index extends Component {

    constructor(props) {
        super(props);
        this.state = {};
    }

    componentDidMount() {
        this.onTrigger()
    }

    onTrigger = () => {
        onListen(topicConstants.onTrigger, (response) => {
            if (!response.success) {
                return
            }

            const code = response.body.plugin.cmdInfo.featureInfo.code
            console.info("code", code)
            if (code == "package") {
                this.doPackagePlugin(response.body)
            }
            else if (code == "install") {
                this.doInstallPlugin(response.body)
            }
        })
    }


    doPackagePlugin = (request) => {
        onEmit(topicConstants.packagePlugin, request.extInfo.path)
    }


    doInstallPlugin = (request) => {
        onEmit(topicConstants.installPlugin, request.extInfo.path)

    }

    render() {
        return (<div></div >);
    }
}


export default Index;